{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构建数据\n",
    "\n",
    "```py\n",
    "import random\n",
    "f = open('data.txt', 'w')\n",
    "stu = ['Bernard', 'Kluicer', 'Anton', 'Falcon', 'Zima']\n",
    "\n",
    "\n",
    "def randTime():\n",
    "    t = str(random.randint(6, 19)).zfill(2)\n",
    "    m = str(random.randint(0, 59)).zfill(2)\n",
    "    s = str(random.randint(0, 59)).zfill(2)\n",
    "    return t+':'+m+':'+s\n",
    "\n",
    "\n",
    "print('ID\\tname\\tamount\\tpos\\tdate\\ttime', file=f)\n",
    "\n",
    "ordId = 0\n",
    "\n",
    "for day in range(1, 6):\n",
    "    for _ in range(random.randint(5*2, 5*3+3)):\n",
    "        ordId += 1\n",
    "        name = random.choice(stu)\n",
    "        amount = random.randint(60, 200)/10\n",
    "        pos = random.randint(1, 6)\n",
    "        tm = randTime()\n",
    "        print(str(ordId)+'\\t'+name+'\\t'+str(amount)+'\\t' +\n",
    "              str(pos)+'\\t'+'Sept '+str(day)+'\\t'+tm, file=f)\n",
    "```\n",
    "\n",
    "![数据](https://img-blog.csdnimg.cn/img_convert/64d7bf01b126024bda8a0554b2b9479e.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 载入数据\n",
    "\n",
    "顺便看看数据的基本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>name</th>\n",
       "      <th>amount</th>\n",
       "      <th>pos</th>\n",
       "      <th>date</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Bernard</td>\n",
       "      <td>11.5</td>\n",
       "      <td>3</td>\n",
       "      <td>Sept 1</td>\n",
       "      <td>17:24:38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Falcon</td>\n",
       "      <td>15.4</td>\n",
       "      <td>6</td>\n",
       "      <td>Sept 1</td>\n",
       "      <td>10:58:44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Zima</td>\n",
       "      <td>18.4</td>\n",
       "      <td>1</td>\n",
       "      <td>Sept 1</td>\n",
       "      <td>10:59:23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Kluicer</td>\n",
       "      <td>14.3</td>\n",
       "      <td>1</td>\n",
       "      <td>Sept 1</td>\n",
       "      <td>12:19:25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Zima</td>\n",
       "      <td>13.4</td>\n",
       "      <td>6</td>\n",
       "      <td>Sept 1</td>\n",
       "      <td>10:52:31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>415</th>\n",
       "      <td>416</td>\n",
       "      <td>Anton</td>\n",
       "      <td>13.7</td>\n",
       "      <td>1</td>\n",
       "      <td>Sept 30</td>\n",
       "      <td>18:17:08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>416</th>\n",
       "      <td>417</td>\n",
       "      <td>Falcon</td>\n",
       "      <td>13.5</td>\n",
       "      <td>4</td>\n",
       "      <td>Sept 30</td>\n",
       "      <td>18:12:27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>418</td>\n",
       "      <td>Bernard</td>\n",
       "      <td>13.2</td>\n",
       "      <td>5</td>\n",
       "      <td>Sept 30</td>\n",
       "      <td>17:49:35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>418</th>\n",
       "      <td>419</td>\n",
       "      <td>Kluicer</td>\n",
       "      <td>17.8</td>\n",
       "      <td>4</td>\n",
       "      <td>Sept 30</td>\n",
       "      <td>07:23:55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>419</th>\n",
       "      <td>420</td>\n",
       "      <td>Kluicer</td>\n",
       "      <td>19.8</td>\n",
       "      <td>6</td>\n",
       "      <td>Sept 30</td>\n",
       "      <td>18:42:24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>420 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      ID     name  amount  pos     date      time\n",
       "0      1  Bernard    11.5    3   Sept 1  17:24:38\n",
       "1      2   Falcon    15.4    6   Sept 1  10:58:44\n",
       "2      3     Zima    18.4    1   Sept 1  10:59:23\n",
       "3      4  Kluicer    14.3    1   Sept 1  12:19:25\n",
       "4      5     Zima    13.4    6   Sept 1  10:52:31\n",
       "..   ...      ...     ...  ...      ...       ...\n",
       "415  416    Anton    13.7    1  Sept 30  18:17:08\n",
       "416  417   Falcon    13.5    4  Sept 30  18:12:27\n",
       "417  418  Bernard    13.2    5  Sept 30  17:49:35\n",
       "418  419  Kluicer    17.8    4  Sept 30  07:23:55\n",
       "419  420  Kluicer    19.8    6  Sept 30  18:42:24\n",
       "\n",
       "[420 rows x 6 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_table('data.txt')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "a9661a0f83c933cf25e0dd40af67627cb20747a37143c65b775945a664681eb4"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
